package com.wfy.orchestra.thread

import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit

/**
 * @author : wangfengyuan
 * e-mail  : 446950883@qq.com
 * time    : 2025/3/20
 * desc    :
 * version : 1.0
 */
class SingleExecutor() : ITaskExecutor {
    private val defaultExecutor: ExecutorService = Executors.newSingleThreadExecutor()

    override fun execute(runnable: Runnable) = defaultExecutor.execute(runnable)
    override fun shutdown() {
        // 强制终止任务线程池 确保线程池彻底关闭
        if (!defaultExecutor.isShutdown) {
            defaultExecutor.shutdown()
            defaultExecutor.awaitTermination(1, TimeUnit.SECONDS)
        }
    }
}